<?php
namespace app\admin\validate;
use app\validate\Common;
use think\Validate;
use think\Db;
class Admin extends Common
{
	/*验证规则*/
	protected $rule = [
		//'account'		=> 'require',
		'old_pwd'		=> 'require|pwd',
		'new_pwd'		=> 'require|regex:pwd',
		'query_pwd'		=> 'twoPwd:new_pwd',
	];
	/*验证提示信息*/
	protected $message = [
		'old_pwd.require'		=> '初始密码不能为空',
		'old_pwd.regex'			=> '初始密码格式错误',
		'old_pwd.pwd'			=> '初始密码不正确',
		'new_pwd.require'		=> '新密码不能为空',
		'new_pwd.regex'			=> '新密码格式错误',
		'query_pwd.twoPwd'		=> '两次密码不一致',
	];
	/*验证场景*/
	protected $scene = [
		'add'	=> ['old_pwd','query_pwd','new_pwd'],
	];

	//密码验证
	protected function pwd($value, $rule, $data)
	{
		$count = Db::name('Admin')
		->where('admin_id',session('admin.admin_id'))
		->where('password',get_pwd($value,config('overall.PWD_STR')))
		->count();
		return $count == 0 ? false : true;
	}
	//两次密码验证
	protected function twoPwd($value, $rule, $data)
	{
		return $value !== $data[$rule] ? false : true;
	}
}